package generator.website;

import java.util.Iterator;
import org.eclipse.emf.common.util.EList;
import website.*;

public class WebSitePageFactory
{
  protected static String nl;
  public static synchronized WebSitePageFactory create(String lineSeparator)
  {
    nl = lineSeparator;
    WebSitePageFactory result = new WebSitePageFactory();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "<%@ page language=\"java\" contentType=\"text/html; charset=ISO-8859-1\" pageEncoding=\"ISO-8859-1\"%>" + NL + "<%@ taglib prefix=\"html\" uri=\"http://struts.apache.org/tags-html\" %>" + NL + "<%@ taglib prefix=\"bean\" uri=\"http://struts.apache.org/tags-bean\" %>" + NL + "<%@ taglib prefix=\"logic\" uri=\"http://struts.apache.org/tags-logic\" %>" + NL + "<%@ taglib prefix=\"nested\" uri=\"http://struts.apache.org/tags-nested\" %>" + NL + "<html:html>" + NL + "<head>" + NL + "<title><bean:message key=\"";
  protected final String TEXT_2 = ".title\"/></title>" + NL + "</head>" + NL + "<body>";
  protected final String TEXT_3 = NL + "\t\t<html:link href=\"";
  protected final String TEXT_4 = ".do\" ><bean:message key=\"";
  protected final String TEXT_5 = ".";
  protected final String TEXT_6 = "\" /></html:link><br/>";
  protected final String TEXT_7 = NL + "\t\t<label><bean:message key=\"";
  protected final String TEXT_8 = ".";
  protected final String TEXT_9 = "\" /></label><br/>";
  protected final String TEXT_10 = NL + "\t\t<html:img srcKey=\"";
  protected final String TEXT_11 = ".";
  protected final String TEXT_12 = "\" /><br/>";
  protected final String TEXT_13 = NL + "\t\t<p><bean:message key=\"";
  protected final String TEXT_14 = ".";
  protected final String TEXT_15 = "\" /></p><br/>";
  protected final String TEXT_16 = NL + "\t\t<html:errors/>" + NL + "\t\t<html:form action=\"/";
  protected final String TEXT_17 = "\"><br/>";
  protected final String TEXT_18 = NL + "\t\t\t\t<html:textarea property=\"";
  protected final String TEXT_19 = "\"></html:textarea><br/>";
  protected final String TEXT_20 = NL + "\t\t\t\t<html:checkbox property=\"";
  protected final String TEXT_21 = "\" /><br/>";
  protected final String TEXT_22 = NL + "\t\t\t\t\t\t<html:text";
  protected final String TEXT_23 = NL + "\t\t\t\t\t\t<html:password";
  protected final String TEXT_24 = " property=\"";
  protected final String TEXT_25 = "\" size=\"";
  protected final String TEXT_26 = "\" maxlength=\"";
  protected final String TEXT_27 = "\" styleId=\"";
  protected final String TEXT_28 = "\"/><br/>";
  protected final String TEXT_29 = NL + "\t\t\t\t\t<html:date property=\"";
  protected final String TEXT_30 = "\" /><br/>";
  protected final String TEXT_31 = NL + "\t\t\t\t\t<html:submit property=\"";
  protected final String TEXT_32 = "\"><bean:message key=\"";
  protected final String TEXT_33 = ".";
  protected final String TEXT_34 = "\" /></html:submit><br/>";
  protected final String TEXT_35 = NL + "\t\t\t\t\t<html:reset property=\"";
  protected final String TEXT_36 = "\"><bean:message key=\"";
  protected final String TEXT_37 = ".";
  protected final String TEXT_38 = "\" /></html:reset><br/>";
  protected final String TEXT_39 = NL + "\t\t\t\t\t<html:radio property=\"";
  protected final String TEXT_40 = "\" value=\"";
  protected final String TEXT_41 = "\" ><bean:message key=\"";
  protected final String TEXT_42 = ".";
  protected final String TEXT_43 = ".";
  protected final String TEXT_44 = "\" /></html:radio><br/>";
  protected final String TEXT_45 = NL + "\t\t\t\t\t<html:select property=\"";
  protected final String TEXT_46 = "\">";
  protected final String TEXT_47 = "<html:option value=\"";
  protected final String TEXT_48 = "\" ><bean:message key=\"";
  protected final String TEXT_49 = ".";
  protected final String TEXT_50 = ".";
  protected final String TEXT_51 = "\" /></html:option><br/>";
  protected final String TEXT_52 = "</html:select>";
  protected final String TEXT_53 = NL + "\t\t\t\t\t\t<html:link href=\"";
  protected final String TEXT_54 = ".do\" ><bean:message key=\"";
  protected final String TEXT_55 = ".";
  protected final String TEXT_56 = "\" /></html:link><br/>";
  protected final String TEXT_57 = NL + "\t\t\t\t\t\t<label for=\"";
  protected final String TEXT_58 = "\"><bean:message key=\"";
  protected final String TEXT_59 = ".";
  protected final String TEXT_60 = "\" /></label> ";
  protected final String TEXT_61 = NL + "\t\t\t\t\t\t<html:img srcKey=\"";
  protected final String TEXT_62 = ".";
  protected final String TEXT_63 = "\" /><br/>";
  protected final String TEXT_64 = NL + "\t\t\t\t\t\t<p><bean:message key=\"";
  protected final String TEXT_65 = ".";
  protected final String TEXT_66 = "\" /></p><br/>";
  protected final String TEXT_67 = NL + "\t\t\t</html:form>";
  protected final String TEXT_68 = NL + "</body>" + NL + "</html:html>";

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
     Page page = (Page) argument; 
    stringBuffer.append(TEXT_1);
    stringBuffer.append(page.getName());
    stringBuffer.append(TEXT_2);
    EList<PageTag> pageTags = page.getPageTags();
for(PageTag pageTag : pageTags){
	if(pageTag instanceof Link){
		Link link = (Link)pageTag;
		
    stringBuffer.append(TEXT_3);
    stringBuffer.append(link.getName());
    stringBuffer.append(TEXT_4);
    stringBuffer.append(page.getName());
    stringBuffer.append(TEXT_5);
    stringBuffer.append(link.getName());
    stringBuffer.append(TEXT_6);
     
	} else if(pageTag instanceof Label){
		
    stringBuffer.append(TEXT_7);
    stringBuffer.append(page.getName());
    stringBuffer.append(TEXT_8);
    stringBuffer.append(pageTag.getName());
    stringBuffer.append(TEXT_9);
     
	} else if(pageTag instanceof Image){
		
    stringBuffer.append(TEXT_10);
    stringBuffer.append(page.getName());
    stringBuffer.append(TEXT_11);
    stringBuffer.append(pageTag.getName());
    stringBuffer.append(TEXT_12);
     
	} else if(pageTag instanceof Paragraph){
		
    stringBuffer.append(TEXT_13);
    stringBuffer.append(page.getName());
    stringBuffer.append(TEXT_14);
    stringBuffer.append(pageTag.getName());
    stringBuffer.append(TEXT_15);
     
	}
		}
EList<Form> pageForms = page.getForms();
	for(Form pageForm : pageForms){
		
    stringBuffer.append(TEXT_16);
    stringBuffer.append(pageForm.getType().getName());
    stringBuffer.append(pageForm.getEntity().getName());
    stringBuffer.append(TEXT_17);
    
		EList<Tag> tags = pageForm.getTags();
			for(Tag tag : tags){
				if(tag instanceof TextArea) {
				
    stringBuffer.append(TEXT_18);
    stringBuffer.append(tag.getName());
    stringBuffer.append(TEXT_19);
    
				} else if(tag instanceof CheckBox) {
				CheckBox checkBox = (CheckBox)tag;
				
    stringBuffer.append(TEXT_20);
    stringBuffer.append(checkBox.getText());
    stringBuffer.append(TEXT_21);
    
				} else if(tag instanceof TextBox) {
					TextBox textBox = (TextBox) tag;
					if(textBox.getType() == TextType.getByName("text") || textBox.getType() == TextType.getByName("email")) {
						
    stringBuffer.append(TEXT_22);
    
					} else {
						
    stringBuffer.append(TEXT_23);
    
					} 
					
    stringBuffer.append(TEXT_24);
    stringBuffer.append(textBox.getName());
    stringBuffer.append(TEXT_25);
    stringBuffer.append(textBox.getSize());
    stringBuffer.append(TEXT_26);
    stringBuffer.append(textBox.getMaxLength());
    stringBuffer.append(TEXT_27);
    stringBuffer.append(textBox.getId());
    stringBuffer.append(TEXT_28);
    
				} else if(tag instanceof Date) {
					
    stringBuffer.append(TEXT_29);
    stringBuffer.append(tag.getName());
    stringBuffer.append(TEXT_30);
    
				} else if(tag instanceof SubmitButton) {
					
    stringBuffer.append(TEXT_31);
    stringBuffer.append(tag.getName());
    stringBuffer.append(TEXT_32);
    stringBuffer.append(page.getName());
    stringBuffer.append(TEXT_33);
    stringBuffer.append(tag.getName());
    stringBuffer.append(TEXT_34);
    
				} else if(tag instanceof ResetButton) {
					
    stringBuffer.append(TEXT_35);
    stringBuffer.append(tag.getName());
    stringBuffer.append(TEXT_36);
    stringBuffer.append(page.getName());
    stringBuffer.append(TEXT_37);
    stringBuffer.append(tag.getName());
    stringBuffer.append(TEXT_38);
    
				} else if(tag instanceof RadioButton) {
					RadioButton radioButton = (RadioButton) tag;
					EList<Element> elements = radioButton.getElements();
					for(Element element : elements){
					
    stringBuffer.append(TEXT_39);
    stringBuffer.append(radioButton.getName());
    stringBuffer.append(TEXT_40);
    stringBuffer.append(element.getValue());
    stringBuffer.append(TEXT_41);
    stringBuffer.append(page.getName());
    stringBuffer.append(TEXT_42);
    stringBuffer.append(radioButton.getName());
    stringBuffer.append(TEXT_43);
    stringBuffer.append(element.getValue());
    stringBuffer.append(TEXT_44);
    
					}
				} else if(tag instanceof Select) {
					Select select = (Select) tag;
					EList<Element> elements = select.getElements();
					
    stringBuffer.append(TEXT_45);
    stringBuffer.append(select.getName());
    stringBuffer.append(TEXT_46);
    
					for(Element element : elements){
					
    stringBuffer.append(TEXT_47);
    stringBuffer.append(element.getValue());
    stringBuffer.append(TEXT_48);
    stringBuffer.append(page.getName());
    stringBuffer.append(TEXT_49);
    stringBuffer.append(select.getName());
    stringBuffer.append(TEXT_50);
    stringBuffer.append(element.getValue());
    stringBuffer.append(TEXT_51);
    
					} 
					
    stringBuffer.append(TEXT_52);
    
				} else if(tag instanceof PageTag) {
					if(tag instanceof Link){
						Link link = (Link)tag;
						
    stringBuffer.append(TEXT_53);
    stringBuffer.append(link.getName());
    stringBuffer.append(TEXT_54);
    stringBuffer.append(page.getName());
    stringBuffer.append(TEXT_55);
    stringBuffer.append(link.getName());
    stringBuffer.append(TEXT_56);
     
					} else if(tag instanceof Label) {
						
    stringBuffer.append(TEXT_57);
    stringBuffer.append(tag.getId());
    stringBuffer.append(TEXT_58);
    stringBuffer.append(page.getName());
    stringBuffer.append(TEXT_59);
    stringBuffer.append(tag.getName());
    stringBuffer.append(TEXT_60);
     
					} else if(tag instanceof Image){
						
    stringBuffer.append(TEXT_61);
    stringBuffer.append(page.getName());
    stringBuffer.append(TEXT_62);
    stringBuffer.append(tag.getName());
    stringBuffer.append(TEXT_63);
     
					} else if(tag instanceof Paragraph){
						
    stringBuffer.append(TEXT_64);
    stringBuffer.append(page.getName());
    stringBuffer.append(TEXT_65);
    stringBuffer.append(tag.getName());
    stringBuffer.append(TEXT_66);
     
					}						
				}
			}
			
    stringBuffer.append(TEXT_67);
    	
		}			

    stringBuffer.append(TEXT_68);
    return stringBuffer.toString();
  }
}
